import service from '@/utils/request.js'

/**
 * 获取当前登录用户的信息
 * @returns {Promise} - 返回用户信息
 */
export const getUserInfo = () => {
  return service({
    url: '/user/chat/info',
    method: 'GET',
    setting: {
      isToken: true
    }
  });
};

/**
 * 获取当前登录用户的所有会话记录id列表
 * @returns {Promise} - 返回会话记录id列表
 */
export const getUserConversations = () => {
  return service({
    url: '/user/chat/conversations',
    method: 'GET',
    setting: {
      isToken: true
    }
  });
};

/**
 * 根据会话id获取该会话的所有消息记录
 * @param {string} id - 会话id
 * @returns {Promise} - 返回消息记录列表
 */
export const getMessagesByConversationId = (id) => {
  return service({
    url: `/user/chat/messages/${id}`,
    method: 'GET',
    setting: {
      isToken: true
    }
  });
};

/**
 * 重命名会话标题
 * @param {string} memoryId - 会话id
 * @param {string} newTitle - 新标题
 * @returns {Promise} - 返回操作结果
 */
export const renameConversation = (memoryId, newTitle) => {
  return service({
    url: `/user/chat/conversations/${memoryId}/rename`,
    method: 'PUT',
    params: {
      title: newTitle
    },
    setting: {
      isToken: true
    }
  });
};

/**
 * 删除会话
 * @param {string} memoryId - 会话id
 * @returns {Promise} - 返回操作结果
 */
export const deleteConversation = (memoryId) => {
  return service({
    url: `/user/chat/conversations/${memoryId}`,
    method: 'DELETE',
    setting: {
      isToken: true
    }
  });
};

/**
 * 置顶/取消置顶会话
 * @param {string} memoryId - 会话id
 * @param {string} isTop - 是否置顶 ("0"取消置顶, "1"置顶)
 * @returns {Promise} - 返回操作结果
 */
export const toggleConversationTop = (memoryId, isTop) => {
  return service({
    url: `/user/chat/conversations/${memoryId}/top`,
    method: 'PUT',
    params: {
      isTop: isTop
    },
    setting: {
      isToken: true
    }
  });
};
